package com.qx.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.AllArgsConstructor;

import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@Table(name = "modules")
public class Modules {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String name;
	private Integer parentid;
	private String path;
	private Integer weight;
	private String icon_class;
	private String ops;
	private Integer int0;

	@JsonIgnore
	// 指定多对多关系，默认懒加载，只有调用getter方法时才加载数据
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rolemodules", // 指定第三张中间表名称
			joinColumns = { @JoinColumn(name = "moduleid") }, // 本表主键
			inverseJoinColumns = { @JoinColumn(name = "roleid") }) // 多对多关系另一张表
	// NotFound:意思是找不到引用的外键数据时忽略，NotFound默认是exception
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Roles> rlist = new ArrayList<Roles>();

	public String test5() {
		return "Modules [id=" + id + ", name=" + name + ", parentid=" + parentid + ", path=" + path + ", weight="
				+ weight + ", icon_class=" + icon_class + ", ops=" + ops + ", int0=" + int0 + ", rlist=" + rlist + "]";
	}

//	@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL) //在实体类自连接一对多关系，查询过多作废
//    @JoinColumn(name = "parentid")
//	private List<Modules> mlist = new ArrayList<Modules>();

}
